﻿namespace PlugNT.Cms.Core
{
    using PlugNT.Cms.BLL;
    using PlugNT.Cms.Model;
    using PlugNT.Custom;
    using PlugNT.Database.Common.Simple;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;

    public class Table
    {
        public static bool CreateTable(string postfix, List<TableType> args)
        {
            bool flag = false;
            List<string> sQLStringList = new List<string>();
            string str3 = WebConfig.DbType;
            if (str3 != null)
            {
                if (str3 == "System.Data.OleDb")
                {
                    return flag;
                }
                if (!(str3 == "System.Data.SqlClient"))
                {
                }
            }
            foreach (TableType type in args)
            {
                string[] createTableSql = GetCreateTableSql(type);
                foreach (string str in createTableSql)
                {
                    if (str != "")
                    {
                        if ( (type == TableType.Article))
                        {
                            sQLStringList.Add(string.Format(str, postfix));
                        }
                        else
                        {
                            sQLStringList.Add(str);
                        }
                    }
                }
            }
            if (sQLStringList.Count > 0)
            {
                string error = "";
                bool flag2 = DbHelper.ExecuteSqlTran(sQLStringList, out error) > 0;
                flag = (error == "") && flag2;
            }
            return flag;
        }

        public static bool DeleteTable(string postfix, List<TableType> args)
        {
            bool flag = false;
            TablesInfo tablesInfoByPostfix = new Tables().GetTablesInfoByPostfix(postfix);
            if ((tablesInfoByPostfix != null) && (tablesInfoByPostfix.postfix != ""))
            {
                List<string> sQLStringList = new List<string>();
                string str3 = WebConfig.DbType;
                if (str3 != null)
                {
                    if (str3 == "System.Data.OleDb")
                    {
                        return flag;
                    }
                    if (!(str3 == "System.Data.SqlClient"))
                    {
                    }
                }
                foreach (TableType type in args)
                {
                    string[] deleteTableSql = GetDeleteTableSql(type);
                    foreach (string str in deleteTableSql)
                    {
                        if (str != "")
                        {
                            sQLStringList.Add(string.Format(str, postfix.ToString()));
                        }
                    }
                }
                if (sQLStringList.Count > 0)
                {
                    string error = "";
                    DbHelper.ExecuteSqlTran(sQLStringList, out error);
                    flag = error == "";
                }
            }
            return flag;
        }

        private static string[] GetCreateTableSql(TableType tType)
        {
            switch (tType)
            {
                case TableType.Adminer:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "article{0}] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [no] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [images] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [title] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [subtitle] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [keyword] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [description] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clslist] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [contents] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [jumpurl] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [info] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [url] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [tip] [int] NULL ,\r\n\t                    [tag] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [hits] [int] NULL ,\r\n\t                    [orders] [int] NULL ,\r\n\t                    [commend] [bit] NOT NULL ,\r\n\t                    [stick] [bit] NOT NULL ,\r\n\t                    [publish] [bit] NOT NULL ,\r\n\t                    [switchs] [int] NULL ,\r\n\t                    [addtime] [smalldatetime] NULL ,\r\n\t                    [createpath] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [pagename] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [previouspage] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [nextpage] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [extend1] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [extend2] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [extend3] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [extend4] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [extend5] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "article{0}] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "article{0}] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "article{0}]([no]) ON [PRIMARY]\r\n                    "), ("\r\n                     CREATE  INDEX [" + WebConfig.TablePrefix + "suoyin] ON [dbo].[" + WebConfig.TablePrefix + "article{0}]([title], [clsno], [clslist]) ON [PRIMARY]\r\n                    ") };

                case TableType.Article:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "comment{0}] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [username] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [ip] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [locked] [bit] NOT NULL ,\r\n\t                    [title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [content] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [addtime] [smalldatetime] NULL ,\r\n\t                    [articleid] [int] NULL ,\r\n\t                    [address] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [tip] [int] NULL ,\r\n\t                    [layer] [int] NULL \r\n                    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "comment{0}] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "comment{0}] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    ") };

                case TableType.Category:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "adminer] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [no] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [password] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [money] [int] NULL ,\r\n\t                    [qq] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [email] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [age] [int] NULL ,\r\n\t                    [logintime] [smalldatetime] NULL ,\r\n\t                    [sex] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [pic] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [power] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [username] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "adminer] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "adminer] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "adminer]([no]) ON [PRIMARY]\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "adminer] VALUES('201011111647312968','admin','21218cca77804d2ba1922c33e0151105',0,'354990393','354990393@qq.com',30,'2010-11-11 16:47:00','男','none','0','none')\r\n                    ") };

                case TableType.Channel:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "category] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [clsno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clslist] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsparentno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clslistlen] [smallint] NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "category] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "category] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "category]([clsno]) ON [PRIMARY]\r\n                     ") };

                case TableType.Comment:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "channel] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [clsno] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clstag] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [clslist] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsparentno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clslistlen] [int] NULL ,\r\n\t                    [indexfile] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [listfile] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [showfile] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [createpath] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [ismap] [smallint] NULL ,\r\n\t                    [navigation] [ntext] COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "channel] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "channel] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "channel]([clsno]) ON [PRIMARY]\r\n                    ") };

                case TableType.Field:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "field] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [tabpostfix] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [title] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [htmltype] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [htmldepth] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [defaultvalue] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [bindclslist] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [isbindsub] [bit] NULL ,\r\n\t                    [column] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [coltype] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [order] [smallint] NULL,\r\n\t                    [length] [smallint] NULL, \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "field] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "field] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "field] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [DF_" + WebConfig.TablePrefix + "field_isbindsub] DEFAULT (0) FOR [isbindsub]\r\n                    "), ("\r\n                     CREATE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "field]([tabpostfix]) ON [PRIMARY]\r\n                    ") };

                case TableType.Friendlink:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "friendlink] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [clsno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [targeturl] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [description] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [text] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "friendlink] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "friendlink] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    ") };

                case TableType.FriendlinkClass:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "friendlink_class] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [clsno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [clsname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "friendlink_class] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "friendlink_class] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "friendlink_class]([clsno]) ON [PRIMARY]\r\n                    ") };

                case TableType.Groupadmin:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "groupadmin] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [power] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [codelist] [ntext] COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "groupadmin] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "groupadmin] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "groupadmin] VALUES('201007061515053281','后台编辑','ASP.admin_article_edit_aspx,ASP.admin_article_admin_aspx,ASP.admin_article_add_aspx,')\r\n                    ") };

                case TableType.Grouppages:
                    return new string[] { 
                        ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "grouppages] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [codeno] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [pagename] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [pagepath] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [groupname] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "grouppages] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "grouppages] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "grouppages]([codeno]) ON [PRIMARY]\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_modifypass_aspx','修改密码','/Admin/ModifyPass.aspx','全局')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_adminer_edit_aspx','修改管理员','/Admin/Adminer/Edit.aspx','模块-管理员管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_adminer_add_aspx','添加管理员','/Admin/Adminer/Add.aspx','模块-管理员管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_adminer_admin_aspx','管理员管理','/Admin/Adminer/Admin.aspx','模块-管理员管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_systems_manager_aspx','系统管理','/Admin/Systems/Manager.aspx','全局-系统管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_uploadimage_aspx','图片上传','/Admin/UploadImage.aspx','全局')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_article_edit_aspx','编辑文章','/Admin/Article/Edit.aspx','核心-内容管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_article_admin_aspx','文章管理','/Admin/Article/Admin.aspx','核心-内容管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_article_add_aspx','添加文章','/Admin/Article/Add.aspx','核心-内容管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_grouppages_edit_aspx','页面权限编辑','/Admin/GroupPages/Edit.aspx','模块-页面授权管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_grouppages_admin_aspx','页面授权列表','/Admin/GroupPages/Admin.aspx','模块-页面授权管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_grouppages_add_aspx','添加页面','/Admin/GroupPages/Add.aspx','模块-页面授权管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_groupadmin_edit_aspx','修改权限组','/Admin/GroupAdmin/Edit.aspx','模块-权限组管理')\r\n                    "), 
                        ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_groupadmin_admin_aspx','权限组列表','/Admin/GroupAdmin/Admin.aspx','模块-权限组管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_groupadmin_add_aspx','添加新组','/Admin/GroupAdmin/Add.aspx','模块-权限组管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_global_config_aspx','基本设置','/Admin/Global/Config.aspx','全局-站点配置')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_global_setcommentfilter_aspx','评论设置','/Admin/Global/SetCommentfilter.aspx','全局-站点配置')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_global_setpayment_aspx','支付配置','/Admin/Global/SetPayment.aspx','全局-站点配置')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_friendlink_linkcategory_aspx','链接位置管理','/Admin/FriendLink/LinkCategory.aspx','模块-友情连接管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_friendlink_edit_aspx','编辑友情连接','/Admin/FriendLink/Edit.aspx','模块-友情连接管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_friendlink_delete_aspx','删除友情连接','/Admin/FriendLink/Delete.aspx','模块-友情连接管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_friendlink_admin_aspx','管理友情链接','/Admin/FriendLink/Admin.aspx','模块-友情连接管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_friendlink_add_aspx','添加链接','/Admin/FriendLink/Add.aspx','模块-友情连接管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_filemanager_edit_aspx','编辑文件','/Admin/FileManager/Edit.aspx','全局-文件管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_filemanager_default_aspx','文件管理','/Admin/FileManager/Default.aspx','全局-文件管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_create_bindtemplet_aspx','绑定模板文件','/Admin/Create/BindTemplet.aspx','核心-绑定文件')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_create_docreate_aspx','生成操作','/Admin/Create/DoCreate.aspx','核心-生成静态')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_create_createhtml_aspx','生成文件','/Admin/Create/CreateHtml.aspx','核心-生成静态')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_systems_sqllist_aspx','SQL语句列表','/Admin/Systems/SqlList.aspx','核心- SQL语句列表')\r\n                    "), 
                        ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_systems_editsqls_aspx','添加和修改','/Admin/Systems/EditSqls.aspx','核心- SQL语句列表')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_user_admin_aspx','用户列表','/Admin/User/Admin.aspx','模块-用户列表')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_user_edit_aspx','修改用户','/Admin/User/Edit.aspx','模块-用户列表')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_user_add_aspx','添加用户','/Admin/User/Add.aspx','模块-用户列表')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_tables_admin_aspx','数据表管理','/Admin/Tables/Admin.aspx','核心-扩展表管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_tables_edittable_aspx','添加或修改','/Admin/Tables/EditTable.aspx','核心-扩展表管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_create_editdynamictemplet_aspx','动态页面','/Admin/Create/EditDynamicTemplet.aspx','核心-绑定文件')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_filemanager_fcktemplets_aspx','修改编辑器模板','/Admin/FileManager/FckTemplets.aspx','全局-文件管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_comment_admin_aspx','评论管理','/Admin/Comment/Admin.aspx','模块-评论管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_comment_reply_aspx','评论回复','/Admin/Comment/Reply.aspx','模块-评论管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_channel_add_aspx','添加新栏目','/Admin/Channel/Add.aspx','核心-栏目管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_channel_edit_aspx','网站栏目修改','/Admin/Channel/Edit.aspx','核心-栏目管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_channel_admin_aspx','网站栏目','/Admin/Channel/Admin.aspx','核心-栏目管理')\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "grouppages] VALUES('ASP.admin_global_setusers_aspx','用户接口','/Admin/Global/SetUsers.aspx','全局-网站配置')\r\n\r\n                    ")
                     };

                case TableType.Sys:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "sys] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [articleupdated] [bit] NOT NULL ,\r\n\t                    [commentfilter] [ntext] COLLATE Chinese_PRC_CI_AS NULL,\r\n\t                    [usersadminhtml] [ntext] COLLATE Chinese_PRC_CI_AS NULL\r\n                    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "sys] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "sys] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "sys] VALUES(1,'法{2}轮,falun,falundafa,六{2}四',\r\n                    '<tr>\r\n                        <td width=''145'' align=''right'' nowrap bgcolor=''#F4FBFF''>用户名:</td>\r\n                        <td width=''1040'' bgcolor=''#F4FBFF''>\r\n                            <input name=''nam_username'' type=''text'' value='''' />                              \r\n                        </td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td align=''right'' nowrap bgcolor=''#F4FBFF''>性别:</td>\r\n                        <td bgcolor=''#F4FBFF''>\r\n                            <input name=''nam_sex'' type=''text'' value='''' />\r\n                        </td>\r\n                    </tr>')\r\n                    ") };

                case TableType.Tables:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "tables] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [postfix] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [dicpath] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [description] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [bindclslist] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [crecomment] [bit] NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "tables] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "tables] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "tables] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [DF_" + WebConfig.TablePrefix + "tables_crecomment] DEFAULT (0) FOR [crecomment]\r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weiyi] ON [dbo].[" + WebConfig.TablePrefix + "tables]([postfix]) ON [PRIMARY]\r\n                    "), ("\r\n                    INSERT [dbo].[" + WebConfig.TablePrefix + "tables] VALUES('','html','默认表','',1)\r\n                    ") };

                case TableType.User:
                    return new string[] { ("\r\n                    CREATE TABLE [dbo].[" + WebConfig.TablePrefix + "user] (\r\n\t                    [id] [int] IDENTITY (1, 1) NOT NULL ,\r\n\t                    [username] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [password] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [nickname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [money] [int] NULL ,\r\n\t                    [qq] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [email] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [age] [int] NULL ,\r\n\t                    [logintime] [smalldatetime] NULL ,\r\n\t                    [sex] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,\r\n\t                    [pic] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [power] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,\r\n\t                    [integral] [int] NULL \r\n                    ) ON [PRIMARY]\r\n                    "), ("\r\n                    ALTER TABLE [dbo].[" + WebConfig.TablePrefix + "user] WITH NOCHECK ADD \r\n\t                    CONSTRAINT [PK_" + WebConfig.TablePrefix + "user] PRIMARY KEY  CLUSTERED \r\n\t                    (\r\n\t\t                    [id]\r\n\t                    )  ON [PRIMARY] \r\n                    "), ("\r\n                     CREATE  UNIQUE  INDEX [" + WebConfig.TablePrefix + "weyi] ON [dbo].[" + WebConfig.TablePrefix + "user]([username]) ON [PRIMARY]\r\n                    ") };
            }
            return new string[] { "" };
        }

        private static string[] GetDeleteTableSql(TableType tType)
        {
            switch (tType)
            {
                case TableType.Adminer:
                    return new string[] { ("\r\n                    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + WebConfig.TablePrefix + "article{0}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\r\n                    drop table [dbo].[" + WebConfig.TablePrefix + "article{0}]\r\n                    ") };

                case TableType.Article:
                    return new string[] { ("\r\n                    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + WebConfig.TablePrefix + "comment{0}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\r\n                    drop table [dbo].[" + WebConfig.TablePrefix + "comment{0}]\r\n                    ") };
            }
            return new string[] { "" };
        }

        public static Dictionary<string, string[]> GetShemaTables()
        {
            int num3;
            string str;
            DataTable table2;
            int num4;
            string[] strArray;
            int num6;
            Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
            DataTable oleDbSchemaTable = null;
            int count = 0;
            string str4 = WebConfig.DbType;
            if (str4 != null)
            {
                if (!(str4 == "System.Data.OleDb"))
                {
                    if (str4 == "System.Data.SqlClient")
                    {
                    }
                }
                else
                {
                    OleDbConnection connection = new OleDbConnection();
                    connection.ConnectionString = WebConfig.ConnectionString;
                    connection.Open();
                    object[] restrictions = new object[4];
                    restrictions[3] = "TABLE";
                    oleDbSchemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, restrictions);
                    count = oleDbSchemaTable.Rows.Count;
                    int index = oleDbSchemaTable.Columns.IndexOf("TABLE_NAME");
                    for (num3 = 0; num3 < count; num3++)
                    {
                        DataRow row = oleDbSchemaTable.Rows[num3];
                        str = row.ItemArray.GetValue(index).ToString();
                        restrictions = new object[4];
                        restrictions[2] = str;
                        table2 = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, restrictions);
                        num4 = table2.Rows.Count;
                        strArray = new string[num4];
                        int num5 = table2.Columns.IndexOf("COLUMN_NAME");
                        num6 = 0;
                        while (num6 < num4)
                        {
                            DataRow row2 = table2.Rows[num6];
                            strArray[num6] = row2.ItemArray.GetValue(num5).ToString();
                            num6++;
                        }
                        dictionary.Add(str, strArray);
                    }
                    connection.Close();
                    connection.Dispose();
                    connection = null;
                    return dictionary;
                }
            }
            oleDbSchemaTable = DbHelper.TabQuery("SELECT Name FROM " + WebConfig.DbName + "..SysObjects Where XType='U' ORDER BY Name ");
            count = oleDbSchemaTable.Rows.Count;
            for (num3 = 0; num3 < count; num3++)
            {
                str = oleDbSchemaTable.Rows[num3]["Name"].ToString();
                table2 = DbHelper.TabQuery("SELECT Name FROM SysColumns WHERE id=Object_Id('" + str + "')");
                num4 = table2.Rows.Count;
                strArray = new string[num4];
                for (num6 = 0; num6 < num4; num6++)
                {
                    strArray[num6] = table2.Rows[num6]["Name"].ToString();
                }
                dictionary.Add(str, strArray);
            }
            return dictionary;
        }

        public static bool ModifyTable(FieldActionType ftype, FieldInfo field)
        {
            bool flag = false;
            string format = "ALTER TABLE [" + Article.GetTableName(field.tabpostfix) + "] {0} " + field.column + " {1} ";
            string str2 = "";
            string str3 = field.coltype;
            if (str3 != null)
            {
                if (!(str3 == "string"))
                {
                    if (str3 == "integer")
                    {
                        if (field.length == 2)
                        {
                            str2 = "[smallint] NULL";
                        }
                        else
                        {
                            str2 = "[int] NULL";
                        }
                    }
                    else if (str3 == "datetime")
                    {
                        str2 = "[smalldatetime] NULL";
                    }
                }
                else if (field.length == 0)
                {
                    str2 = "[ntext] COLLATE Chinese_PRC_CI_AS NULL";
                }
                else
                {
                    str2 = "[nvarchar] (" + field.length.ToString() + ") COLLATE Chinese_PRC_CI_AS NULL";
                }
            }
            switch (ftype)
            {
                case FieldActionType.add:
                    format = string.Format(format, "ADD", str2);
                    break;

                case FieldActionType.update:
                    format = string.Format(format, "ALTER COLUMN", str2);
                    break;

                case FieldActionType.delete:
                    format = string.Format(format, "DROP COLUMN", "");
                    break;

                default:
                    format = "";
                    break;
            }
            if (format != "")
            {
                DbHelper.ExecuteSql(format);
                flag = true;
            }
            return flag;
        }
    }
}

